package NO6_Tree;

/**
 * 2025-08-15
 * 力扣 - 226. 翻转二叉树
 * <p>
 * 给你一棵二叉树的根节点 root ，翻转这棵二叉树，并返回其根节点。
 */
public class InvertTreeMain {
    public static void main(String[] args) {
        TreeNode root = new TreeNode(4, new TreeNode(2, new TreeNode(1), new TreeNode(3)), new TreeNode(7, new TreeNode(6), new TreeNode(9)));
//        TreeNode.printTree(root);
        System.out.println("\n----------------");
        TreeNode.printTree(invertTree(root));
    }

    public static TreeNode invertTree(TreeNode root) {
        if (root == null) {
            return null;
        }

        root.left = invertTree(root.left);
        root.right = invertTree(root.right);
        return new TreeNode(root.val, root.right, root.left);
    }
}
